package Model;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JProgressBar;



public class RunMonteCarloSimulation implements Runnable {

	private MonteCarloSimulation monteCarlo;
	private JButton button;
	private int nb;
	private Option option;
	private JProgressBar progress;
	private JLabel[] results;
	private JLabel[] time;
	
	public RunMonteCarloSimulation(MonteCarloSimulation monteCarlo, JButton button, JProgressBar progress, JLabel[] results, JLabel[] elapsedTime , Option option, int nb){
		this.monteCarlo=monteCarlo;
		this.button=button;
		this.option=option;
		this.nb=nb;
		this.progress=progress;
		this.results=results;
		this.time=elapsedTime;
	}
	
	@Override
	public void run() {
		double result;
		progress.setMinimum(0);
		progress.setMaximum(nb-1);
		for(int i=0; i<nb;i++){
			double begin = System.nanoTime();
			result=monteCarlo.standartOption(option.getFlag(), option.getS(), option.getX(), option.getT(), option.getR(), option.getB(), option.getV(), option.getnSteps(),option.getnSimulations());
			double end = System.nanoTime();
			progress.setValue(i);
			results[i].setText("Output: "+result);
			time[i].setText("Excution time: "+(end-begin)/1000000000+"s");
		}
		button.setVisible(true);
		progress.setValue(0);
		
	}

}
